@extends('layouts.admin')
@section('style')
@endsection
@section('content')
    <div class="layui-container openframe">
        <form class="layui-form" method="get" action="{{ url('choice/shop') }}">
            <input type="hidden" name="type" value="{{ $choice_type }}" />
            <div class="layui-form-item" style="padding:5px;">
                    <div class="layui-input-inline" style="width:100px;">
                        <select name="opt_type" >
                            <option value="title" @if($opt_type=='title') selected @endif >商家名称</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="margin-left:-8px;width:300px;">
                        <input type="text" name="keywords" value="{{ $keywords }}" class="layui-input" placeholder="输入关键词"   />
                    </div>
                    <div class="layui-input-inline" style="margin-left:-8px;width:120px!important;">
                        <select name="catid">
                            <option value="">选择商家分类</option>
                            @foreach($categorys as $category)
                                <option value="{{ $category->id }}" @if($category->id==$catid) selected @endif >{{ $category->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-input-inline" style="margin-left:-8px;width:120px!important;">
                        <a href="javascript:void(0)" lay-submit lay-filter="btn_query" class="layui-btn layui-btn-warm">查询</a>
                    </div>
              </div>
        </form>
        <table class="layui-table layui-form">
            <colgroup>
                <col width="50" />
                <col width="50" />
                <col width=""/>
                <col width="150" />
                <col width="250"/>
                <col width="100"/>
            </colgroup>
            <thead>
            <tr>
                <th></th>
                <th>ID</th>
                <th>名称</th>
                <th>分类</th>
                <th>城区</th>
                <th>状态</th>
            </tr>
            </thead>
            <tbody>
            @foreach($datas as $vo)
                <tr>
                    @if($choice_type==1)
                        <td><input type="checkbox" lay-skin="primary" name="ids[]" data-name="{{ $vo->title }}" value="{{ $vo->id }}" title=""></td>
                    @else
                        <td><input type="radio" name="id" data-name="{{ $vo->title }}" value="{{ $vo->id }}" title=""></td>
                    @endif
                    <td>{{ $vo->id }}</td>
                    <td>{{ $vo->title }}</td>
                    <td>{{ !is_null($vo->category)?$vo->category->name:'' }}</td>
                    <td>{{ $vo->location() }}</td>
                    <td>{{ $vo->viewcontent('status') }}</td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        var doSave = null;
        var count =parseInt("{{ isset($counts)?$counts:0 }}");
        var limit =parseInt("{{ isset($limit)?$limit:1  }}");
        var currPage =parseInt("{{ isset($page)?$page:1  }}");
        var _choice_type = parseInt("{{ $choice_type }}");
        layui.use(['jquery','form','layer','xmPage','utils'],function(){
            var $ = layui.$,
                form = layui.form,
                URL = layui.utils.URL,
                layer = layui.layer;

            if(count>0){
                var xmPage = layui.xmPage({
                    formElem:'#ListForm',
                    limit:limit,
                    count:count,
                    curr:currPage,
                    layout:['prev','page','next','skip','count','limit'],
                    prev:'<i class="layui-icon">&#xe65a;</i>',
                    next:'<i class="layui-icon">&#xe65b;</i>',
                });
                xmPage.render();
            }
            form.on('submit(btn_query)',function(data){
                var _form = $(data.form);
                _form.submit();
            });

            form.on('submit(btn_query)',function(data){
                var _form = $(data.form);
                _form.submit();
            });
            doSave =function(callback){
                if(_choice_type==1){
                    var _checked = $("input[type=checkbox]:checked");
                }else{
                    var _checked = $("input[type=radio]:checked");
                }
                if(_checked.length<=0){
                    layer.msg('请选择商家',{icon:5,time:1000});
                    return -1;
                }
                if(_choice_type==1){
                    var _data = new Array();
                    for(var i=0;i<_checked.length;i++){
                        var _id = _checked.eq(i).val();
                        var _name = _checked.eq(i).data('name');
                        _data[i] = {id:_id,name:_name};
                    }
                }else{
                    var _id = _checked.eq(0).val();
                    var _name = _checked.eq(0).data('name');
                    var _data ={id:_id,name:_name};
                }
                callback.call(this,_data);
            }
        })
    </script>
@endsection